package collection.project.practice;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/*
    collection练习：
 */
public class PracticeMain {
    public static void main(String[] args) {
        Collection collection = new ArrayList();
        Student student1 = new Student("小三",22);
        Student student2 = new Student("小四",24);
        Student student3 = new Student("小五",23);
        collection.add(student1);
        collection.add(student2);
        collection.add(student3);
        System.out.println(collection.size());
        System.out.println(collection.toString());
        collection.remove(student1);
        System.out.println(collection.size());
        //这个remove并没有将之前创建的Student1给删除，因为他们是两个对象
        //collection.remove(new Student("小三",22));
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()){
            Student s = (Student) iterator.next();//因为对象是Student类型，所以要强转
            System.out.println(s.toString());
        }
    }
}
